const express = require('express')
const pool = require('../pool')
const router = express.Router()
module.exports = router
// 首页数据
router.get('/scenic', (req, res, next) => {
	// 轮播图数据
	pool.query('SELECT * FROM xh_index_carousel', (err, result1) => {
		if (err) {
			next(err)
			return
		}
		// 首页景点数据
		pool.query('SELECT * FROM xh_scenic', (err,
			result2) => {
			if (err) {
				next(err)
				return
			}
			// 首页类别
			pool.query('SELECT * FROM xh_category_family', (err, result4) => {
				if (err) {
					next(err)
					return
				}
				res.send({
					code: 200,
					message: '操作成功',
					carouselItem: result1,
					scenicIndex: result2,
					scenicFamily: result4
				})
			})
		})
	})
})
// 首页搜索
router.get('/search', (req, res, next) => {
	let text = req.query.items;
	pool.query(`SELECT * FROM xh_scenic WHERE title like '%${text}%'`, text, (err, data) => {
		if (err) {
			next(err)
			return
		}
		res.send({
			code: 200,
			message: 'OK',
			data: data
		})
	})
})


module.exports = router;
